Last chance! 50% off unlimited learning
Sale ends in
Create an encrypted message (sealed box) from a curve25519 public key.
simple_encrypt(msg, pubkey)simple_decrypt(bin, key)
message to be encrypted
public key of the receiver
encrypted ciphertext
private key of the receiver
Simple public key encryption allows for sending anonymous encrypted messages to a recipient given its public key. Only the recipient can decrypt these messages, using its private key.
While the recipient can verify the integrity of the message, it cannot verify the identity of the sender. For sending authenticated encrypted messages, use auth_encrypt and auth_decrypt.
https://doc.libsodium.org/public-key_cryptography/sealed_boxes.html
# Generate keypair
key <- keygen()
pub <- pubkey(key)
# Encrypt message with pubkey
msg <- serialize(iris, NULL)
ciphertext <- simple_encrypt(msg, pub)
# Decrypt message with private key
out <- simple_decrypt(ciphertext, key)
stopifnot(identical(out, msg))
Run the code above in your browser using DataLab